package com.hxy.controller;


import com.github.pagehelper.PageInfo;
import com.hxy.common.JsonResult;
import com.hxy.pojo.Paydetail;
import com.hxy.pojo.model.PayRecordSelectData;
import com.hxy.pojo.vo.PaydetailVo;
import com.hxy.pojo.vo.PayrecordVo;
import com.hxy.service.PaydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 工资明细(Paydetail)表控制层
 *
 * @author feiyu
 * @since 2021-11-03 09:41:31
 */
@RestController
@RequestMapping("/paydetail")
public class PaydetailController {
    /**
     * 服务对象
     */
    @Autowired
    private PaydetailService paydetailService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping("/selectOne")
    public JsonResult selectOne(Long id) {
        if (id!=null){
            PaydetailVo paydetailVo = this.paydetailService.selectPaydetailVo(id);
            return new JsonResult(0,"success",paydetailVo);
        }
        else {
            return new JsonResult(1,"fail",null);
        }
    }

    /**
     * 模糊查询工资详情
     * @param page
     * @param limit
     * @param stuffName
     * @param startTime
     * @param endTime
     * @param branchid
     * @return
     */
    @RequestMapping("/selectPageInfoAll")
    public JsonResult selectPageInfoAll(
                                        @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                        @RequestParam(value = "limit", required = false, defaultValue = "10") int limit,
                                        @RequestParam(value = "stuffname", required = false, defaultValue = "") String stuffName,
                                        @RequestParam(value = "starttime", required = false, defaultValue = "") String startTime,
                                        @RequestParam(value = "endtime", required = false, defaultValue = "") String endTime,
                                        @RequestParam(value = "branchid", required = false, defaultValue = "") Integer branchid
                                       ){
        page = page == null ? 1 : page;
        PayRecordSelectData payRecordSelectData = new PayRecordSelectData();
        //封装数据
        payRecordSelectData.setPage(page);
        payRecordSelectData.setLimit(limit);
        payRecordSelectData.setStuffname(stuffName);
        payRecordSelectData.setStarttime(startTime);
        payRecordSelectData.setEndtime(endTime);
        if (branchid!=null){
            payRecordSelectData.setBranchid(branchid.toString());
        }
        //调用service方法
        System.out.println("调用service方法"+payRecordSelectData);
        PageInfo<PaydetailVo> paydetailVo=paydetailService.selectDetailPageInfoAll(payRecordSelectData);
        if (paydetailVo!=null){
        return new JsonResult(0,"success",paydetailVo);
        }
        else {
            return new JsonResult(1,"fail",null);
        }
    }

    /**
     * 修改明细
     * @param paydetail
     * @return
     */
    @RequestMapping("/update")
    public JsonResult update(PaydetailVo paydetail){
        JsonResult jsonResult = paydetailService.update(paydetail);
        return jsonResult;
    }


}